import Taro from '@tarojs/taro';

export default function (chain) {
  const requestParams = chain.requestParams;
  const { header } = requestParams;
  // console.log('request', requestParams);
  // const token = 'mBEAxQK4OdEoQw5XrwkhxjgKzgpK85CAEfu0I7NxD3FDWGe9AE4qL0jDQYUd' || Taro.getStorageSync('token');
  const token = Taro.getStorageSync('token');
  if (token) {
    requestParams.header = {
      ...header,
      Authorization: 'Bearer ' + token,
    };
  }
  // console.log(`http ${method || 'GET'} --> ${url} data: `, data);

  return chain.proceed(requestParams).then((res) => {
    return res;
  });
}
